var week = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
var num = ["0 1 2 4 5 6", "2 5", "0 2 3 4 6", "0 2 3 5 6", "1 2 3 5", "0 1 3 5 6", "0 1 3 4 5 6", "0 2 5", "0 1 2 3 4 5 6", "0 1 2 3 5 6"]
window.onload = function () {
    showTime();
    setInterval(function(){
        showTime();
    },500);
}
function showTime() {
    var now = new Date();
    var y = now.getFullYear();
    var M = now.getMonth() + 1;
    var d = now.getDate();
    var h = now.getHours();
    var m = now.getMinutes();
    var s = now.getSeconds();
    var str = y.toString() + "年" + buling(M) + "月" + buling(d) + "日";
    document.getElementById("date").getElementsByTagName("span")[0].innerHTML = str;
    document.getElementById("date").getElementsByTagName("span")[1].innerHTML = week[now.getDay()];

    modiflyNumpic(1, parseInt(h / 10));
    modiflyNumpic(2, h % 10);
    modiflyNumpic(3, parseInt(m / 10));
    modiflyNumpic(4, m % 10);
    modiflyNumpic(5, parseInt(s / 10));
    modiflyNumpic(6, s % 10);
}
//补零功能
function buling(i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}
//修改要显示的图片
function modiflyNumpic(id, value){
    var elm = document.getElementById('time' + id.toString()).getElementsByTagName('li');
    var numstr = num[value];
    var cc = numstr.split(' ');
    for (var i = 0; i < 7; i++) {
        elm[i].getElementsByTagName('img')[0].src = "images/back.png";
    }
    for (var i = 0; i < cc.length; i++) {
        elm[parseInt(cc[i])].getElementsByTagName('img')[0].src = "images/front.png";
    }
}